import pygame

from Action.Shoot import ShootDir, DirShootByAImage
from Action.Walk import DirWalkByAImage, WalkDir
from Actor.walk_soldier import WalkSoldier


class ShootSoldier(WalkSoldier):
    shoot_image_width = 100
    shoot_image_height = 100

    def __init__(self, work_path: str, shoot_action: str, pos_x, pos_y, name, hp):
        super(ShootSoldier, self).__init__(work_path, pos_x, pos_y, name, hp)
        self.walk_action = DirWalkByAImage(work_path,
                                           self.image_width, self.image_height, True)
        self.shoot_action = DirShootByAImage(shoot_action,
                                             self.shoot_image_width, self.shoot_image_height, True)

        self.shoot_action.set_dir(ShootDir.not_shoot)

    # 0 下 1 左  2 右 3 上
    def run(self, down_flag, key_list):
        self.shoot_action.set_dir(ShootDir.not_shoot)
        super(ShootSoldier, self).run(down_flag, key_list)
        if down_flag:
            if key_list[pygame.K_q]:
                self.shoot_action.set_dir(ShootDir.left_up)
            elif key_list[pygame.K_a]:
                self.shoot_action.set_dir(ShootDir.left_down)
            elif key_list[pygame.K_e]:
                self.shoot_action.set_dir(ShootDir.right_up)
            elif key_list[pygame.K_d]:
                self.shoot_action.set_dir(ShootDir.right_down)
            elif key_list[pygame.K_w]:
                self.walk_action.set_dir(WalkDir.up)
                self.shoot_action.set_dir(ShootDir.up)
            elif key_list[pygame.K_s]:
                self.walk_action.set_dir(WalkDir.down)
                self.shoot_action.set_dir(ShootDir.down)

    def draw(self, surface: pygame.Surface, x, y):
        """
        绘制
        :param surface:
        :param x:
        :param y:
        :return:
        """
        if self.shoot_action.shoot_dir == ShootDir.not_shoot:
            super(ShootSoldier, self).draw(surface, x, y)
        elif self.shoot_action.shoot_dir == ShootDir.down:
            current_image = self.shoot_action.get_image()
            surface.blit(current_image, (self.pos_x - x, self.pos_y - y))
            current_image = self.walk_action.get_image()
            surface.blit(current_image, (self.pos_x, self.pos_y))
        elif self.shoot_action.shoot_dir == ShootDir.up:
            current_image = self.shoot_action.get_image()
            surface.blit(current_image, (self.pos_x - x, self.pos_y - y - 60))
            current_image = self.walk_action.get_image()
            surface.blit(current_image, (self.pos_x - x, self.pos_y - y))
        else:
            current_image = self.shoot_action.get_image()
            surface.blit(current_image, (self.pos_x - x, self.pos_y - y))
